package net.huashitong.question.service;

import com.sirdc.modules.core.dao.BaseDao;
import com.sirdc.modules.sys.base.StringPKService;
import com.sirdc.modules.sys.service.SysTableService;
import com.sirdc.modules.utils.StringUtils;
import net.huashitong.question.dao.TaskRecordDao;
import net.huashitong.question.entity.TaskRecord;
import net.huashitong.question.filter.TaskRecordFilter;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TaskRecordService extends StringPKService<TaskRecord> {
    @Autowired
    private TaskRecordDao dao;
    @Autowired
    private SysTableService tableService;

    @Override
    protected BaseDao<TaskRecord, String> getDao() {
        return dao;
    }

    @Override
    protected void beforeSave(TaskRecord obj) {
        obj.setSysId(tableService.updateMaxSysId("t_task_record", null));
    }

    /**
     * 保存节点信息
     * @param filter
     */
    public boolean saveRocord(TaskRecordFilter filter)
    {
        if(StringUtils.isBlank(filter.getDataTime())
                ||StringUtils.isBlank(filter.getRecord())){
            System.out.println("记录填写不规范");
            return false;
        }else{
            TaskRecord record = new TaskRecord();
            BeanUtils.copyProperties(filter,record);
            save(record);
            return true;
        }
    }

    /**
     * 根据任务Id 获取所有完成情况
     * @param taskid
     * @return
     */
    public List<TaskRecord> getRecordsById(String taskid)
    {
        return dao.getResDeptRecordsbyId(taskid);
    }

}
